/**
 * 
 */
package kr.co.magic;

import kr.co.magic.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

/**
 * @author johnkim
 *
 */
public class SignatureView extends Activity {
	public static final String TAG = SignatureView.class.getSimpleName();
	
	/*
	 * 프레임웍 구성 변수 선언
	 */
	LinearLayout drawLayout;
	LinearLayout keyboardLayout;
	LinearLayout keyboardTextarealayout;
	RelativeLayout pageMoveLayout;
	
	// 페인트 view 변수
	private PaintView paintView;
	
	// Canvas의 프레임 길이
	final int maxFrameLength = 934;

	// Canvas의 최대 이동 가능 값.
	int maxDistance = 0;
	
	// Canvas의 이동 가능 거리.
	int distance = 0;
	
	// Canvas의 default 이동값
	int defaultX = 700;
	
	// Canvas image의 길이.
	int image_width = 12000;
	
	// Canvas image의 높이.
	int image_height = 315;
	
	Button btnConfirm;
	Button btnClear;
	Button btnExit;


	/** Called when the activity is first created. */
	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.signature);
		
		paintView = (PaintView) findViewById(R.id.paintView);
		
		initActivity();
		
		btnConfirm = (Button)findViewById(R.id.btnConfirm);
		btnConfirm.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				DongyangView.signature = paintView.getBitmap();
				Log.e(TAG, "DongyangView.signature.getRowBytes : " + DongyangView.signature.getRowBytes());
				
				Toast.makeText(SignatureView.this, "서명파일이 생성되었습니다.", Toast.LENGTH_SHORT).show();
				
				finish();
			}
		});
		
		btnClear = (Button)findViewById(R.id.btnClear);
		btnClear.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onCreate(savedInstanceState);
			}
		});
		
		btnExit = (Button)findViewById(R.id.btnExit);
		btnExit.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
		Log.e(TAG, "onCreate");
	}

	/**
	 * 화면 초기화 
	 */
	private void initActivity() {
		initPaintView(image_width);
	}
	
	/**
	 * paintView page 크기 변수
	 */
	private int paint_page_limit = 0;

	/**
	 * Canvas 오른쪽으로 이동
	 */
	 private void scrollRightPaintView() {
/*
		int mX = defaultX + distance;
		int nowPage = paintView.getNowPaintPageNum();
		if(nowPage < paint_page_limit){
			paintView.extendImage();
		}
		if (mX < maxDistance && nowPage < paint_page_limit) {
			if(nowPage+1 == paint_page_limit){
				mX = distance+(defaultX - paintView.getRemainWidth());
				drawLayout.scrollTo(mX, 0);
			}else {
				drawLayout.scrollTo(mX, 0);
			}
			distance = mX;
			paintView.moveToRightPaintView();
			eform.invalidate();
			nowPage = paintView.getNowPaintPageNum();
		} else {
			Toast.makeText(EFormActivity.this, getString(R.string.form_endpaintpage_str), Toast.LENGTH_SHORT)
					.show();
		}
*/
	}

	/**
	 * Canvas 왼쪽으로 이동.
	 */
/*
	private void scrollLeftPaintView() {
		int mX = 0;
		int nowPage = paintView.getNowPaintPageNum();
		if(nowPage == paint_page_limit){
			mX = distance - (defaultX - paintView.getRemainWidth());
		} else if(nowPage-1 == 1){
			mX = -1;
		} else {
			mX = distance - defaultX;
		}
		if (mX > 0) {
			drawLayout.scrollTo(mX, 0);
			distance = mX;
			paintView.moveToLeftPaintView();
			eform.invalidate();
		} else {
			if(distance > 0){
				distance = 0;
				drawLayout.scrollTo(0, 0);
				paintView.moveToLeftPaintView();
				eform.invalidate();
			} 
			Toast.makeText(EFormActivity.this, getString(R.string.form_firstpaintpage_str), Toast.LENGTH_SHORT)
					.show();

		}
	}
*/

	/**
	 * Canvas 초기화
	 * 
	 * @param imageLength
	 */
	private void initPaintView(int imageLength) {
		maxDistance = imageLength - maxFrameLength;
		distance = 0;
	}
	
}
